home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / Starfield3.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  1.6 KB  |  52 lines

  1. ' Star field demo 3
  2. '
  3. ' Varying star's brightness using OpenGL fog
  4.  
  5. const maxStars = 1000
  6.  
  7. dim stars#(maxStars)(2)
  8. dim i
  9.  
  10. ' Populate star field
  11. for i = 1 to maxStars
  12.     stars#(i) = vec3 (rnd () % 401 - 200, rnd () % 401 - 200, -i)
  13. next
  14.  
  15. glDisable (GL_DEPTH_TEST)
  16.  
  17. ' Setup OpenGL fog.
  18. ' This instructs OpenGL to fog out objects that are in the distance, by
  19. ' gradually changing their colour to the fog colour. We will use black.
  20. ' Once fog is setup it is all automatic. We don't need to worry about setting
  21. ' the star's colours.
  22. glEnable (GL_FOG)
  23. glFogi (GL_FOG_MODE, GL_LINEAR)             ' Objects fade out linearly
  24. glFogf (GL_FOG_END, maxStars)               ' Objects past this distance are totally faded
  25. glFogf (GL_FOG_START, 0)                    ' Objects before this distance are totally un-faded
  26. glFogfv (GL_FOG_COLOR, vec3 (0, 0, 0))      ' Fog colour = black
  27. ' Note:
  28. '   These are all versions of the glFog command.
  29. '   glFogi takes an integer parameter (i = integer)
  30. '   glFogf takes a floating point parameter (f = float)
  31. '   glFogfv takes a floating point array parameter (f = float, v = array)
  32.  
  33. ' Main loop
  34. while true    
  35.     glClear (GL_COLOR_BUFFER_BIT)       
  36.  
  37.     for i = 1 to maxStars
  38.     
  39.         ' Move the star forward, by adding 1 to Z
  40.         stars#(i) = stars#(i) + vec3 (0, 0, 2)
  41.  
  42.         ' If the Z goes positive (behind the screen), move it to the back again.
  43.         if stars#(i)(2) >= 0 then stars#(i)(2) = -maxStars endif
  44.         
  45.         glBegin (GL_POINTS)
  46.             glVertex3fv (stars#(i))
  47.         glEnd ()
  48.     next
  49.     SwapBuffers ()
  50.     WaitTimer (20)
  51. wend
  52.